#include "../hle.h"

SceUID sasCoreUid = -1;

void __sceSasCore()
{
    u32 sasCore = PARAM(0);
    u32 sasOut = PARAM(1);
    if (mem_isOk(sasCore) && mem_read32(sasCore) == sasCoreUid) {
        _log(INF, HLE, "0 = __sceSasCore(sasCore = %08x, sasOut = %08x)", sasCore, sasOut);
        RETURN(0);
    }
    else {
        _log(ERR, HLE, "-1 = __sceSasCore(sasCore = %08x, sasOut = %08x): invalid sasCore", sasCore, sasOut);
        RETURN(SCE_ERROR_SAS_NOT_INIT);
    }
}

void __sceSasGetEndFlag()
{
    _log(ERR, HLE, "ffffffff = __sceSasGetEndFlag()");
    RETURN(0xffffffff);
}

void __sceSasSetVolume()
{
    u32 sasCore = PARAM(0);
    s32 num = PARAM(1);
    s32 l = PARAM(2);
    s32 el = PARAM(3);
    s32 r = PARAM(4);
    s32 er = PARAM(5);
    _log(ERR, HLE, "0 = __sceSasSetVolume(sasCore = %08x, voicenum = %d, l = %d, r = %d, el = %d, er = %d", sasCore, num, l, r, el, er);
    RETURN(0);
}

void __sceSasSetPitch()
{
    u32 sasCore = PARAM(0);
    s32 num = PARAM(1);
    s32 pitch = PARAM(2);

    _log(ERR, HLE, "0 = __sceSasSetPitch(sasCore = %08x, voicenum = %d, pitch = %d)", sasCore, num, pitch);
    /* RETURN(0); */
}

void __sceSasSetVoice()
{
    u32 sasCore = PARAM(0);
    s32 num = PARAM(1);
    u32 vagAddr = PARAM(2);
    s32 size = PARAM(3);
    s32 loop = PARAM(4);
    _log(ERR, HLE, "0 = __sceSasSetVoice(sasCore = %08x, voicenum = %d, vag = %08x, size = %d, loop = %d)", 
                                       sasCore,        num,           vagAddr,    size,      loop);

    RETURN(0);
}

void __sceSasSetADSR()
{
    u32 sasCore = PARAM(0);
    s32 num = PARAM(1);
    s32 flag = PARAM(2);
    s32 a = PARAM(3);
    s32 d = PARAM(4);
    s32 s = PARAM(5);
    s32 r = PARAM(6); /* ?? */
    _log(ERR, HLE, "0 = __sceSasSetADSR(sasCore = %08x, voicenum = %d, flag = %d, a = %08x, d = %08x, s = %08x, r = %08x)", 
                                      sasCore,        num,           flag,      a,        d,        s,        r);
    RETURN(0);
}

void __sceSasInit()
{
    u32 sasCore = PARAM(0);
    _log(INF, HLE, "0 = __sceSasInit(sasCore = %08x)", sasCore);
    if (mem_isOk(sasCore)) {
        sasCoreUid = ko_init(NULL, KO_SASCORE);
        mem_write32(sasCore, sasCoreUid);
    }
    RETURN(0);
}

